#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"

void onMouse(int event,int x, int y, int flags, void * param){
    cv::Mat * im = reinterpret_cast<cv::Mat *>(param);
    switch (event) {
    case CV_EVENT_LBUTTONDOWN:
        std::cout<<"at(" <<x<<","<<y<<") value is:"<<static_cast<int>(im->at<uchar>(cv::Point(x,y)))<<std::endl;
        break;
    default:
        break;
    }
}

void test_draw_puttext()
{
    cv::Mat image = cv::imread("/home/iroan-ubuntu16/Project/Coding/GraduationProjectCode/iuc.jpg",CV_LOAD_IMAGE_GRAYSCALE);
//    must be before imshow
    cv::circle(image,cv::Point(120,120),100,255,1);
    cv::putText(image,"ChenGangRong",cv::Point(0,120),cv::FONT_HERSHEY_PLAIN,2.0,255,2);
    cv::imshow("grayscale",image);
    cv::setMouseCallback("grayscale",onMouse,reinterpret_cast<void*>(&image));
    cv::waitKey(0);
}

void test_new_a_img()
{
    cv::Mat image1(240,320,CV_8U,255);
    cv::imshow("image",image1);
    image1.create(200,200,CV_8U);
    cv::imshow("image1",image1);

//     10 is color value
    image1 = 10;
    cv::imshow("image2",image1);
    cv::waitKey(0);
}

void test_img_copy()
{
    cv::Mat image = cv::imread("/home/iroan-ubuntu16/Project/Coding/GraduationProjectCode/iuc.jpg");
    cv::imshow("image",image);
    cv::Mat img1(image);
    cv::imshow("img1",img1);
    cv::Mat img2 = image;
    cv::imshow("img2",img2);
    cv::circle(img1,cv::Point(120,120),100,255,1);
    cv::imshow("img_test",img2);
    cv::waitKey(0);
}

void test_deep_copy()
{
    cv::Mat image = cv::imread("/home/iroan-ubuntu16/Project/Coding/GraduationProjectCode/iuc.jpg");
    cv::imshow("image",image);
    cv::Mat img1;
    image.copyTo(img1);
    cv::circle(img1,cv::Point(120,120),100,20,3);
    cv::imshow("img1",img1);
    cv::imshow("image1",image);
    cv::waitKey(0);
}

void test_create_red_img()
{
    cv::Mat image(240,320,CV_8UC3,cv::Scalar(0,0,255));
    cv::imshow("image",image);
    cv::waitKey(0);
}

void test_ROI()
{
    cv::Mat image = cv::imread("/home/iroan-ubuntu16/Project/Coding/GraduationProjectCode/iuc.jpg");
    cv::Mat logo = cv::imread("/home/iroan-ubuntu16/Project/Coding/GraduationProjectCode/logo.jpg");
    cv::Mat imageROI(image,cv::Rect(10,10,logo.cols,logo.rows));
//    cv::Mat imageROI(image,cv::Range());
    logo.copyTo(imageROI);
    cv::imshow("image",image);
//    cv::imshow("logo",logo);
    cv::waitKey(0);
}

int main(){
//    test_draw_puttext();
//    test_new_a_img();
//    test_img_copy();
//    test_deep_copy();
//    test_create_red_img();
    test_ROI();

    return 0;
}
